package com.yaozi.util;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.velocity.app.event.implement.EscapeReference;

/**
 * velocity html转义，参考{@link org.apache.velocity.app.event.implement.EscapeHtmlReference}
 * Created by wuzheng.yk on 15/10/14.
 */
public class YtEscapeHtmlReference extends EscapeReference {

    public YtEscapeHtmlReference() {

    }

    /**
     * 原来这个类使用的StringEscapeUtils.escapeHtml 是commons.lang包下的，中文会乱码。使用commons.lang3下的没问题
     * @param text
     * @return
     */
    @Override
    protected String escape(Object text) {
        return StringEscapeUtils.escapeHtml4(text.toString());
    }

    @Override
    protected String getMatchAttribute() {
        return "eventhandler.escape.html.match";
    }
}
